﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebMatrix.WebData;

namespace G28BS.Code
{
    public class AppUserService : IUserService
    {
        public int GetUserID()
        {
            int userID = 0;
            try
            {
                userID = WebSecurity.CurrentUserId;
            }
            catch (Exception)
            {
                WebSecurity.InitializeDatabaseConnection(
                    "AppDataContext",
                    "UserProfile",
                    "UserId",
                    "UserName",
                    true);
                userID = WebSecurity.CurrentUserId;
            }
            return userID;
        }

        public string GetUserName()
        {
            string userName = "";
            try
            {
                userName = WebSecurity.CurrentUserName;
            }
            catch (Exception)
            {
                WebSecurity.InitializeDatabaseConnection(
                    "AppDataContext",
                    "UserProfile",
                    "UserId",
                    "UserName",
                    true);
                userName = WebSecurity.CurrentUserName;
            }
            return userName;
        }
    }
}